home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / upc12bs1.zip / UUCP / uuname.c < prev    next >
C/C++ Source or Header  |  1993-05-08  |  7KB  |  207 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    u u n a m e . c                                                 */
  3. /*                                                                    */
  4. /*    Known site lister for UUPC/extended                             */
  5. /*                                                                    */
  6. /*--------------------------------------------------------------------*/
  7.  
  8. /*--------------------------------------------------------------------*/
  9. /*         System include files                                       */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. #include <stdio.h>
  13. #include <io.h>
  14. #include <sys/types.h>
  15. #include <sys/stat.h>
  16. #include <string.h>
  17. #include <time.h>
  18. #include <fcntl.h>
  19. #include <stdlib.h>
  20.  
  21. /*--------------------------------------------------------------------*/
  22. /*         Local include files                                        */
  23. /*--------------------------------------------------------------------*/
  24.  
  25. #include "lib.h"
  26. #include "getopt.h"
  27. #include "hlib.h"
  28. #include "hostable.h"
  29. #include "security.h"
  30. #include "timestmp.h"
  31.  
  32. currentfile();
  33.  
  34. /*--------------------------------------------------------------------*/
  35. /*                             Verb list                              */
  36. /*--------------------------------------------------------------------*/
  37.  
  38. typedef enum {
  39.    LIST_DEFAULT = 1,
  40.    LIST_LOCAL,
  41.    LIST_DOMAIN
  42.    } COMMAND_CLASS;
  43.  
  44. /*--------------------------------------------------------------------*/
  45. /*                        Internal prototypes                         */
  46. /*--------------------------------------------------------------------*/
  47.  
  48. static void all( void );
  49.  
  50. static void local( void );
  51.  
  52. static void domain( void );
  53.  
  54. static void usage( void );
  55.  
  56. /*--------------------------------------------------------------------*/
  57. /*    m a i n                                                         */
  58. /*                                                                    */
  59. /*    main program                                                    */
  60. /*--------------------------------------------------------------------*/
  61.  
  62. void main(int  argc, char  **argv)
  63. {
  64.    int c;
  65.    COMMAND_CLASS command = LIST_DEFAULT;
  66.    extern char *optarg;
  67.    extern int   optind;
  68.  
  69. /*--------------------------------------------------------------------*/
  70. /*     Report our version number and date/time compiled               */
  71. /*--------------------------------------------------------------------*/
  72.  
  73.    debuglevel = 0;
  74.  
  75.    banner( argv );
  76.  
  77. #if defined(__CORE__)
  78.    copywrong = strdup(copyright);
  79.    checkref(copywrong);
  80. #endif
  81.  
  82. /*--------------------------------------------------------------------*/
  83. /*        Process our arguments                                       */
  84. /*--------------------------------------------------------------------*/
  85.  
  86.    while ((c = getopt(argc, argv, "dlx:")) !=  EOF)
  87.       switch(c) {
  88.       case 'x':
  89.          debuglevel = atoi( optarg );
  90.          break;
  91.  
  92.       case 'd':
  93.          command = LIST_DOMAIN;
  94.          break;
  95.  
  96.       case 'l':
  97.          command = LIST_LOCAL;
  98.          break;
  99.  
  100.       case '?':
  101.          usage();
  102.    }
  103.  
  104.    if (optind != argc) {
  105.       puts("Extra parameter(s) at end.");
  106.       exit(2);
  107.    }
  108.  
  109.    if (!configure( B_UUSTAT ))
  110.       exit(1);   /* system configuration failed */
  111.  
  112. /*--------------------------------------------------------------------*/
  113. /*                   Execute the requested command                    */
  114. /*--------------------------------------------------------------------*/
  115.  
  116.    switch ( command )
  117.    {
  118.       case LIST_DEFAULT:
  119.              all( );
  120.              break;
  121.  
  122.       case LIST_LOCAL:
  123.              local( );
  124.              break;
  125.  
  126.       case LIST_DOMAIN:
  127.              domain( );
  128.              break;
  129.  
  130.       default:
  131.              panic();
  132.  
  133.    } /* switch */
  134.  
  135.    exit(0);
  136.  
  137. } /* main */
  138.  
  139. /*--------------------------------------------------------------------*/
  140. /*    a l l                                                           */
  141. /*                                                                    */
  142. /*    Display all connected systems names                             */
  143. /*--------------------------------------------------------------------*/
  144.  
  145. static void all( )
  146. {
  147.    struct HostTable *hostp = nexthost( TRUE );
  148.  
  149. /*--------------------------------------------------------------------*/
  150. /*                  Scan one or all host directories                  */
  151. /*--------------------------------------------------------------------*/
  152.  
  153.    while  (hostp !=  BADHOST )
  154.    {
  155.       printf("%s\n", hostp->hostname);
  156.  
  157. /*--------------------------------------------------------------------*/
  158. /*    If processing all hosts, step to the next host in the queue     */
  159. /*--------------------------------------------------------------------*/
  160.  
  161.       hostp = nexthost( FALSE );
  162.  
  163.    } /* while */
  164.  
  165. } /* all */
  166.  
  167. /*--------------------------------------------------------------------*/
  168. /*    l o c a l                                                       */
  169. /*                                                                    */
  170. /*    Display local systems node name                                 */
  171. /*--------------------------------------------------------------------*/
  172.  
  173. static void local( )
  174. {
  175.    printf("%s\n", E_nodename);
  176. } /* local */
  177.  
  178. /*--------------------------------------------------------------------*/
  179. /*    d o m a i n                                                     */
  180. /*                                                                    */
  181. /*    Display local systems domain name                               */
  182. /*--------------------------------------------------------------------*/
  183.  
  184. static void domain( )
  185. {
  186.    printf("%s\n", E_domain);
  187. } /* domain */
  188.  
  189. /*--------------------------------------------------------------------*/
  190. /*    u s a g e                                                       */
  191. /*                                                                    */
  192. /*    Report how to use program                                       */
  193. /*--------------------------------------------------------------------*/
  194.  
  195. static void usage( void )
  196. {
  197.  
  198.    fputs("Usage:\tuuname\t[-l|-d]\n\
  199. \tDefault is to display all known uucp systems.\n\
  200. \t-d\t\tDisplays local node's domain name.\n\
  201. \t-l\t\tDisplays local node's uucp name.\n",
  202.             stdout );
  203.  
  204.    exit(1);
  205.  
  206. } /* usage */
  207.